const { $Lazy } = window
// ===================================================================== Lazy
const confirm = $Lazy.file(()=>import('@antd/confirm'))
const message = $Lazy.file(()=>import('@antd/message'))
// ===================================================================== 
const Index = function(api, { param, title = '删除', msg, onOk, onMy, onRefresh, onComplete, refresh = true, clear = true, onAwait, width }){
	confirm.then( f => {
		f({
			msg: msg ? msg : `确认${title}？`,
			width,
			onOk: async close => {
				if(onMy){
					onMy(close)
					close()
				}else{
					if(api){
						if(onAwait){ await onAwait?.() }
						window.$http.submit(null,api,{ param, loadingText:`${title}中`, onError:close }).then(async data=>{
							close()
							message.then(f=>f.success(`${title}成功`))
							
							onOk?.()
							
							if(this && !onOk && refresh !== false){ 
								window.$fn.delay(this.fetch)
								
								if(clear !== false){ window.$fn.clearKeys.call(this) }
								
								onRefresh && onRefresh()
							}
							
							onComplete?.()
						})
					}else{
						onOk?.(close)
					}
				}
			}
		})
	})
}

export default Index